<template>
    <div class="index-page">               
            <div class="index-top clearfix">
                <Row :gutter="10">
                    <Col :class="isCollapse ?  'w20' : '' " :xs="24" :ms="24" :md="24"  :style="{marginBottom: '10px'}">                    
                        <div class='account-info top-card fl shadow' :class="animateShow1">
                            <!-- <h4>账户信息</h4> -->
                            <div class="top-bar"></div>
                            <div class="wrap">
                                <div class="info">
                                    <Row>
                                        <Col span="7" offset="1" class="avatar"><img :src="avatar" alt=""></Col>
                                        <Col span="6" offset="1" class="balance">
                                        <!-- <span>0</span> 元</Col> -->
                                        <!-- <Col span="3" offset="1" class="clearing">
                                        <span class="account" style="cursor:pointer">结算</span>
                                        </Col>
                                        <Col span="3" offset="1" class="recharge">
                                        <span class="recharge" style="cursor:pointer">充值</span>
                                        </Col> -->
                                        </Col>
                                    </Row>
                                </div>
                                <div class="safe-lever wrap-item">
                                    <Row>
                                        <Col span="7" offset="1" class="ellipsis">安全等级：</Col>
                                        <Col span="15" class="">
                                        <div class='safe-wrap' style="background-color: #f2f2f2;border-radius:5px;margin-top:5px;">
                                            <div :style="safeBarStyle"></div>
                                        </div>
                                        </Col>
                                    </Row>
                                </div>
                                <div class="account wrap-item">
                                    <Row>
                                        <Col span="6" offset="1" class="">账号：</Col>
                                        <Col span="16" class="ellipsis">{{name}}</Col>
                                    </Row>
                                </div>
                                <div class="company wrap-item">
                                    <Row>
                                        <Col span="6" offset="1" class="">公司：</Col>
                                        <Col span="16" class="ellipsis">{{companyname}}</Col>
                                    </Row>
                                </div>
                            </div>
                        </div>
                    </Col>
                    <Col :class="isCollapse ?  'w20' : '' " :xs="24" :ms="24" :md="24" :style="{marginBottom: '10px'}"> 
                        <div class='quantity-sale top-card fl shadow' :class="animateShow2">
                            <!-- <h4>统计</h4> -->
                            <div class="top-bar"></div>
                            <div class="wrap">
                                <div class="top">
                                    <h5>昨日预收标准保费</h5>
                                    <span class="value">{{initData.yesterday_premium || 0.00}}</span>元
                                </div>
                                <!-- <div class="bottom">
                                    <h5>总保费(元)</h5>
                                    <p class="value">0.00</p>
                                </div> -->
                            </div>
                        </div>
                    </Col>
                    <Col :class="isCollapse ?  'w20' : '' " :xs="24" :ms="24" :md="24" :style="{marginBottom: '10px'}"> 
                        <div class='ranking-sale top-card fl shadow' :class="animateShow3">
                            <!-- <h4>销售排行</h4> -->
                            <div class="top-bar"></div>
                            <div class="wrap">
                                <div class="top">
                                    <h5>昨日预售保单件数</h5>
                                    <span class="value">{{initData.yesterday_count || 0.00}}</span>件
                                </div>
                            </div>
                        </div>
                    </Col>
                    <Col :class="isCollapse ?  'w20' : '' " :xs="24" :ms="24" :md="24" :style="{marginBottom: '10px'}"> 
                        <div class='top-pro top-card fl shadow' :class="animateShow4">
                            <!-- <h4>热销产品</h4> -->
                            <div class="top-bar"></div>
                            <div class="wrap">
                                <div class="top">
                                    <h5>本月承保标准保费</h5>
                                    <span class="value">{{initData.month_premium || 0.00}}</span>元
                                </div>
                            </div>
                        </div>
                    </Col>
                    <Col :class="isCollapse ?  'w20' : '' " :xs="24" :ms="24" :md="24" :style="{marginBottom: '10px'}"> 
                        <div class='top-pro top-card fl shadow' :class="animateShow4">
                            <!-- <h4>热销产品</h4> -->
                            <div class="top-bar"></div>
                            <div class="wrap">
                                <div class="top">
                                    <h5>本月承保标准保费</h5>
                                    <span class="value">{{initData.month_count || 0.00}}</span>件
                                </div>
                            </div>
                        </div>
                    </Col>
                </Row>
            </div>
        <Row class="margin-top-10">
            <div :style="echartWrapStyle">
                <div id="line" style="width:100%;height:100%;" ></div>
            </div>
        </Row>
        <Row class="margin-top-10">
            <div :style="echartWrapStyle">
                <div id="yearLine" style="width:100%;height:100%;" ></div>
            </div>
        </Row>
        <!-- <div :style="echartWrapStyle">       
            <div style="width:100%;height:100%;" id="visite_volume_con"></div>
        </div> -->
    </div>
</template>
<script>
import echarts from 'echarts'
import debounce  from 'lodash.debounce'
import { getData } from '../../api/index'
export default {
    data() {
        return {
            isCollapse:document.body.clientWidth > 1200,
            animateShow1:'',
            animateShow2:'',
            animateShow3:'',
            animateShow4:'',
            echartWrapStyle: {
                backgroundColor:'#fff',
                height:'500px'
            },
            mainStyle: {
                marginTop: '20px',
            },
            safeBarStyle: {
                height: '10px',
                backgroundColor: '#4074e1',
                width: '0',
                borderTopLeftRadius: '5px',
                borderBottomLeftRadius: '5px',
                transition: ' width 1s',
            },
            initData:{},
            serviceRequestCharts:null,
            yearLine:null,
            year:2018,
            month:7
        }
    },
    computed: {
        avatar() {
            return this.$store.state.user.avatar ? this.$store.state.user.avatar : "http://i.kuaibao365.com/tpl/20170829/150397337160390.png";
        },
        name() {
            return this.$store.state.user.name;
        },
        companyname() {
            return this.$store.state.user.name;
        },
        echartsHeight() {
            let winHeight = screen.availHeight;
            return winHeight - 56 -51 -93 -191 -20 -30 +'px' 
        },
    },
    methods: {
        getInitData(){
            getData().then(res=>{
                console.log(res)
                if(res.data.err == 0){
                    this.initData = res.data.data
                    let _day = new Date();
                    let _year = _day.getFullYear();
                    let _month = _day.getMonth() + 1;
                    let _daycount = new Date(_year,_month,0).getDate()

                    this.serviceRequestCharts.setOption({
                        series: [
                            {
                                data: this.initData.month_achievement_count
                            },
                            {
                                data: this.initData.month_achievement_premium
                            },
                        ],
                        xAxis : [
                            {
                                data : new Array(_daycount).toString().split(',').map((item,index)=>{
                                    return (index + 1).toString()
                                })
                            }
                        ],
                    })

                    this.yearLine.setOption({
                        series: [
                            {
                                data: this.initData.year_achievement_count
                            },
                            {
                                data: this.initData.year_achievement_premium
                            },
                        ]
                    })

                }else{
                    this.$Message.error('获取信息失败！')
                }
                
            }).catch(err => {
                this.$Message.error('获取信息失败！')
            })
            .finally(() => {
                this.serviceRequestCharts.resize();
                this.yearLine.resize();
            });
        }
    },
    mounted() {
        let _time = new Date() 
        this.year =  _time.getFullYear()
        this.month = _time.getMonth() + 1
        this.getInitData()
        const option = {
            color: ['#3aa1fe', '#4fcb73'],
            title: {
                text: this.year +'年'+this.month+'月业绩动态走势图',
                left: '3%' ,
                top:'3%' ,
            },
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            legend: {
                data:['件数','标准保费',],
                bottom : 0,
            },
            grid: {
                left: '3%',
                right: '4%',
                top:'15%' ,
                bottom: '5%',
                containLabel: true
            },
            xAxis : [
                {
                    type : 'category',
                    boundaryGap : false,
                    axisTick: {
                        alignWithLabel: true
                    },
                    
                    axisLine: {
                        onZero: false,
                    },
                    data : new Array(30).toString().split(',').map((item,index)=>{
                        return (index + 1).toString()+'日'
                    })
                }
            ],
            yAxis : [
                {   
                    name : '件数/件',
                    type : 'value',
                    splitLine: {
                        show: false
                    }
                },
                {
                    name : '标准保费/万元',    
                    type : 'value',
                    splitLine: {
                        show: false
                    }
                }
            ],
            series : [
                {
                    name:'件数',
                    type:'line',
                    smooth: true,
                    yAxisIndex: 0,
                    data:[],
                },
                {
                    name:'标准保费',
                    type:'line',
                    smooth: true,
                    yAxisIndex: 1,
                    data:[]
                },
            ]
        };
        const serviceRequestCharts = echarts.init(document.getElementById('line'));
        this.serviceRequestCharts = serviceRequestCharts
        serviceRequestCharts.setOption(option);
    
        const option1 = {
            color: ['#3aa1fe', '#4fcb73'],
            title: {
                text: this.year +'年业绩动态走势图',
                left: '3%' ,
                top:'3%' ,
            },
            tooltip : {
                trigger: 'axis',
                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            legend: {
                data:['件数','标准保费',],
                bottom : 0,
            },
            grid: {
                left: '3%',
                right: '4%',
                top:'15%' ,
                bottom: '5%',
                containLabel: true
            },
            xAxis : [
                {
                    type : 'category',
                    axisTick: {
                        alignWithLabel: true
                    },
                    data : ['01月','02月','03月','04月','05月','06月','07月','08月','09月','10月','11月','12月']
                }
            ],
            yAxis : [
                {   
                    name : '件数/件',
                    type : 'value',
                    splitLine: {
                        show: false
                    }
                },
                {
                    name : '标准保费/万元',    
                    type : 'value',
                    splitLine: {
                        show: false
                    }
                }
            ],
            series : [
                {
                    name:'件数',
                    type:'bar',
                    yAxisIndex: 0,
                    data:[]
                },
                {
                    name:'标准保费',
                    type:'bar',
                    yAxisIndex: 1,
                    data:[],                   
                },
            ]
        };

        const yearLine = echarts.init(document.getElementById('yearLine'));
        this.yearLine = yearLine
        yearLine.setOption(option1);

        window.addEventListener('resize', function () {
            serviceRequestCharts.resize();
            yearLine.resize();

        });
        this.safeBarStyle.width = '50%'
        setTimeout(()=>{
             this.animateShow1 = 'active'
        },100)
         setTimeout(()=>{
             this.animateShow2 = 'active'
        },300)
         setTimeout(()=>{
             this.animateShow3 = 'active'
        },500)
         setTimeout(()=>{
             this.animateShow4 = 'active'
        },700)

        window.onresize = debounce(() => {
            const screenWidth = document.body.clientWidth;
            console.log(screenWidth)
            this.isCollapse = screenWidth > 1200;
            
        }, 400);

        // let visiteVolume = echarts.init(document.getElementById('visite_volume_con'));
        // let xAxisData = [];
        // let data1 = [];
        // let data2 = [];
        

        // const options = {
        //     tooltip: {
        //         trigger: 'axis',
        //         axisPointer: {
        //             type: 'shadow'
        //         }
        //     },
        //     grid: {
        //         top: 0,
        //         left: '2%',
        //         right: '10%',
        //         bottom: '3%',
        //         containLabel: true
        //     },
        //     xAxis: {
        //         name:'标准保费（万元）',
        //         type: 'value',
        //         boundaryGap: [0, 0.01]
        //     },
        //     yAxis: {
        //         type: 'category',
        //         data: ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'],
        //         nameTextStyle: {
        //             color: '#c3c3c3'
        //         }
        //     },
        //     series: [
        //         {
        //             name: '访问量',
        //             type: 'bar',
        //             data: [
        //                 {value: 453682, name: 'Mon', itemStyle: {normal: {color: '#2d8cf0'}}},
        //                 {value: 879545, name: 'Tues', itemStyle: {normal: {color: '#2d8cf0'}}},
        //                 {value: 2354678, name: 'Wed', itemStyle: {normal: {color: '#2d8cf0'}}},
        //                 {value: 1598403, name: 'Thur', itemStyle: {normal: {color: '#2d8cf0'}}},
        //                 {value: 543250, name: 'Fri', itemStyle: {normal: {color: '#2d8cf0'}}},
        //                 {value: 1305923, name: 'Sat', itemStyle: {normal: {color: '#2d8cf0'}}},
        //                 {value: 1103456, name: 'Sun', itemStyle: {normal: {color: '#2d8cf0'}}}
        //             ]
        //         }
        //     ]
        // };

        // visiteVolume.setOption(options);

        // window.addEventListener('resize', function () {
        //     visiteVolume.resize();
        // });


    }
}
</script>
<style>
.w20{
    width: 20%;
}
</style>

<style scoped>
.ellipsis{
    overflow: hidden;white-space: nowrap;text-overflow: ellipsis;
}
.margin-top-10{
    margin-top:10px;
}
.index-page {
    height: 100%;
    width: 100%;
    background-color: #edf2f6;
}
.index-page .shadow {
    box-shadow: 0px 0px 5px #999;
}
.index-page .top-card {
    position: relative;
    top:40px;
    /* height: 191px; */
    margin-right: 1.16%;
    width: 100%;
    transition: all 0.8s;
}
.index-page .top-card.active{
    top:0px;
}
.index-page .account-info {
    width: 100%;
}

.index-page .top-pro {
    margin-right: 0;
}

.top-card .wrap {
    width: 100%;
    background-color: #fff;
}

.account-info .wrap {
    /* padding: 0; */
    
    padding:10px 0 15px 0;
}

.top-card .wrap .wrap-item {
    margin-top: 5px;
}

.top-card .top-bar {
    height: 5px;
    width: 100%;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

.top-card.account-info .top-bar {
    background-color: #4074e1;
}

.top-card.quantity-sale .top-bar {
    background-color: #69efe6;
}

.top-card.ranking-sale .top-bar {
    background-color: #ff855e;
}

.top-card.top-pro .top-bar {
    background-color: #adeda1;
}

.index-page .info {
    line-height: 32px;
    text-align: center;
}

.index-page .info .avatar {
    text-align: left;
}

.index-page .info .avatar img {
    width: 32px;
    border: 1px solid #dfdfdf;
    border-radius: 30px;
}

.index-page .info .balance span {
    color: #358bee;
    font-size: 24px;
}

.index-page .info .clearing {
    background-color: #358bf2;
    color: #fff;
    border-radius: 5px;
}

.index-page .info .recharge {
    background-color: #ff6769;
    color: #fff;
    border-radius: 5px;
}

.index-page .ivu-col.ivu-col-span-16 {
    height: 100%;
}

.top-card .wrap h5 {
    font-size: 14px;
    color: #999;
    font-weight: normal;
    text-align: center;
}
.top-card .wrap{
    text-align:center;
}
.top-card .wrap .value {
    
    font-size: 30px;
    color: #4074e1;
    font-weight: 700;
    text-align: center;
}

.top-card .wrap .top {
    padding: 40px 20px;
    border-bottom: 1px solid #efefef;
}

.top-card .wrap .bottom {
    padding: 13px 20px;
}

.top-card .wrap .bottom .value {
    color: #656f7e;
}

#line{
    width: 100%;
}

</style>


